﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PrintDemo.Entity;
using PrintDemo.DBUtil;
using log4net;
using System.Data;
using Dapper;

namespace PrintDemo.DAL
{
    public class BoxNumDAL
    {
        public int InsertOld(BoxNumEntity model)
        {
            try
            {
                string SqlStr = "INSERT INTO Boxnum(Id,OrderId,LineType,FinishedProductName,Batch,Operator,CreateTime,JuanNum,MaoZhong,OneBoxCount,Store,AllCount,BoxNum)values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}')";
                SqlStr = string.Format(SqlStr, new object[] { model.Id, model.OrderId, model.LineType, model.FinishedProductName, model.Batch, model.Operator, model.CreateTime, model.JuanNum, model.MaoZhong, model.OneBoxCount, model.Store, model.AllCount, model.BoxNum });
                SQLFactory.GetMySqlHelper().ExecuteSqlNonQuery(SqlStr);
            }
            catch (Exception ex)
            {
                return -1;
            }
            return 1;
        }

        public IDbConnection Conn
        {
            get
            {
                return MySqlHelper.Conn;
            }
        }

        public int? Insert(BoxNumEntity model)
        {
            try
            {
                StringBuilder sql = new StringBuilder("INSERT INTO Boxnum(Id,OrderId,LineType,FinishedProductName,Batch,Operator,CreateTime,JuanNum,MaoZhong,OneBoxCount,Store,AllCount,BoxNum)");
                sql.Append(" VALUES( @Id,@OrderId,@LineType,@FinishedProductName,@Batch,@Operator,@CreateTime,@JuanNum,@MaoZhong,@OneBoxCount,@Store,@AllCount,@BoxNum)");
                using (Conn)
                {
                    int insert_Result = this.Conn.Execute(sql.ToString(), model);
                    return insert_Result;
                }
            }
            catch (Exception ex)
            {
                //_log.Error("Insert", ex);
                return 0;
            }
        }
    }
}
